﻿// =================================================================== 
// 项目说明
//====================================================================
// Wup。@Copy Right 2014
// 文件： ask.cs
// 项目名称：买车网
// 创建时间：2014/7/20
// 负责人：Wup
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Weixin.Entity.ChinaTax;
using Weixin.Utils;


namespace Weixin.DAL.ChinaTax
{
    /// <summary>
    /// 数据层实例化接口类 dbo.ask.
    /// </summary>
    public partial class askDataAccessLayer 
    {
		#region 构造函数


		/// <summary>
		/// 
		/// </summary>
		public askDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_askModel">ask实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(askEntity _askModel)
		{
			string sqlStr="insert into ask([title],[content],[state],[utime],[dtime],[tag],[isHot],[username],[flag],[RealName],[Mobile],[Email],[SourceId],[hits]) values(@title,@content,@state,@utime,@dtime,@tag,@isHot,@username,@flag,@RealName,@Mobile,@Email,@SourceId,@hits) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@title",SqlDbType.VarChar),
			new SqlParameter("@content",SqlDbType.VarChar),
			new SqlParameter("@state",SqlDbType.Int),
			new SqlParameter("@utime",SqlDbType.DateTime),
			new SqlParameter("@dtime",SqlDbType.DateTime),
			new SqlParameter("@tag",SqlDbType.VarChar),
			new SqlParameter("@isHot",SqlDbType.Int),
			new SqlParameter("@username",SqlDbType.VarChar),
			new SqlParameter("@flag",SqlDbType.Int),
			new SqlParameter("@RealName",SqlDbType.VarChar),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@SourceId",SqlDbType.Int),
			new SqlParameter("@hits",SqlDbType.Int)
			};			
			_param[0].Value=_askModel.title;
			_param[1].Value=_askModel.content;
			_param[2].Value=_askModel.state;
			_param[3].Value=_askModel.utime;
			_param[4].Value=_askModel.dtime;
			_param[5].Value=_askModel.tag;
			_param[6].Value=_askModel.isHot;
			_param[7].Value=_askModel.username;
			_param[8].Value=_askModel.flag;
			_param[9].Value=_askModel.RealName;
			_param[10].Value=_askModel.Mobile;
			_param[11].Value=_askModel.Email;
			_param[12].Value=_askModel.SourceId;
			_param[13].Value=_askModel.hits;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_askModel">ask实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(SqlTransaction sp,askEntity _askModel)
		{
			string sqlStr="insert into ask([title],[content],[state],[utime],[dtime],[tag],[isHot],[username],[flag],[RealName],[Mobile],[Email],[SourceId],[hits]) values(@title,@content,@state,@utime,@dtime,@tag,@isHot,@username,@flag,@RealName,@Mobile,@Email,@SourceId,@hits) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@title",SqlDbType.VarChar),
			new SqlParameter("@content",SqlDbType.VarChar),
			new SqlParameter("@state",SqlDbType.Int),
			new SqlParameter("@utime",SqlDbType.DateTime),
			new SqlParameter("@dtime",SqlDbType.DateTime),
			new SqlParameter("@tag",SqlDbType.VarChar),
			new SqlParameter("@isHot",SqlDbType.Int),
			new SqlParameter("@username",SqlDbType.VarChar),
			new SqlParameter("@flag",SqlDbType.Int),
			new SqlParameter("@RealName",SqlDbType.VarChar),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@SourceId",SqlDbType.Int),
			new SqlParameter("@hits",SqlDbType.Int)
			};			
			_param[0].Value=_askModel.title;
			_param[1].Value=_askModel.content;
			_param[2].Value=_askModel.state;
			_param[3].Value=_askModel.utime;
			_param[4].Value=_askModel.dtime;
			_param[5].Value=_askModel.tag;
			_param[6].Value=_askModel.isHot;
			_param[7].Value=_askModel.username;
			_param[8].Value=_askModel.flag;
			_param[9].Value=_askModel.RealName;
			_param[10].Value=_askModel.Mobile;
			_param[11].Value=_askModel.Email;
			_param[12].Value=_askModel.SourceId;
			_param[13].Value=_askModel.hits;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp,CommandType.Text,sqlStr,_param));
			return res;
		}


		/// <summary>
		/// 向数据表ask更新一条记录。
		/// </summary>
		/// <param name="_askModel">_askModel</param>
		/// <returns>影响的行数</returns>
		public int Update(askEntity _askModel)
		{
            string sqlStr="update ask set [title]=@title,[content]=@content,[state]=@state,[utime]=@utime,[dtime]=@dtime,[tag]=@tag,[isHot]=@isHot,[username]=@username,[flag]=@flag,[RealName]=@RealName,[Mobile]=@Mobile,[Email]=@Email,[SourceId]=@SourceId,[hits]=@hits where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@title",SqlDbType.VarChar),
				new SqlParameter("@content",SqlDbType.VarChar),
				new SqlParameter("@state",SqlDbType.Int),
				new SqlParameter("@utime",SqlDbType.DateTime),
				new SqlParameter("@dtime",SqlDbType.DateTime),
				new SqlParameter("@tag",SqlDbType.VarChar),
				new SqlParameter("@isHot",SqlDbType.Int),
				new SqlParameter("@username",SqlDbType.VarChar),
				new SqlParameter("@flag",SqlDbType.Int),
				new SqlParameter("@RealName",SqlDbType.VarChar),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@SourceId",SqlDbType.Int),
				new SqlParameter("@hits",SqlDbType.Int)
				};				
				_param[0].Value=_askModel.ID;
				_param[1].Value=_askModel.title;
				_param[2].Value=_askModel.content;
				_param[3].Value=_askModel.state;
				_param[4].Value=_askModel.utime;
				_param[5].Value=_askModel.dtime;
				_param[6].Value=_askModel.tag;
				_param[7].Value=_askModel.isHot;
				_param[8].Value=_askModel.username;
				_param[9].Value=_askModel.flag;
				_param[10].Value=_askModel.RealName;
				_param[11].Value=_askModel.Mobile;
				_param[12].Value=_askModel.Email;
				_param[13].Value=_askModel.SourceId;
				_param[14].Value=_askModel.hits;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表ask更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_askModel">_askModel</param>
		/// <returns>影响的行数</returns>
		public int Update(SqlTransaction sp,askEntity _askModel)
		{
            string sqlStr="update ask set [title]=@title,[content]=@content,[state]=@state,[utime]=@utime,[dtime]=@dtime,[tag]=@tag,[isHot]=@isHot,[username]=@username,[flag]=@flag,[RealName]=@RealName,[Mobile]=@Mobile,[Email]=@Email,[SourceId]=@SourceId,[hits]=@hits where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@title",SqlDbType.VarChar),
				new SqlParameter("@content",SqlDbType.VarChar),
				new SqlParameter("@state",SqlDbType.Int),
				new SqlParameter("@utime",SqlDbType.DateTime),
				new SqlParameter("@dtime",SqlDbType.DateTime),
				new SqlParameter("@tag",SqlDbType.VarChar),
				new SqlParameter("@isHot",SqlDbType.Int),
				new SqlParameter("@username",SqlDbType.VarChar),
				new SqlParameter("@flag",SqlDbType.Int),
				new SqlParameter("@RealName",SqlDbType.VarChar),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@SourceId",SqlDbType.Int),
				new SqlParameter("@hits",SqlDbType.Int)
				};				
				_param[0].Value=_askModel.ID;
				_param[1].Value=_askModel.title;
				_param[2].Value=_askModel.content;
				_param[3].Value=_askModel.state;
				_param[4].Value=_askModel.utime;
				_param[5].Value=_askModel.dtime;
				_param[6].Value=_askModel.tag;
				_param[7].Value=_askModel.isHot;
				_param[8].Value=_askModel.username;
				_param[9].Value=_askModel.flag;
				_param[10].Value=_askModel.RealName;
				_param[11].Value=_askModel.Mobile;
				_param[12].Value=_askModel.Email;
				_param[13].Value=_askModel.SourceId;
				_param[14].Value=_askModel.hits;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}		
		
		
		/// <summary>
		/// 删除数据表ask中的一条记录
		/// </summary>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(int ID)
		{
			string sqlStr="delete from ask where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表ask中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(SqlTransaction sp,int ID)
		{
			string sqlStr="delete from ask where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  ask 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>ask 数据实体</returns>
		public askEntity Populate_askEntity_FromDr(DataRow row)
		{
			askEntity Obj = new askEntity();
			if(row!=null)
			{
				Obj.ID = (( row["ID"])==DBNull.Value)?0:Convert.ToInt32( row["ID"]);
				Obj.title =  row["title"].ToString();
				Obj.content =  row["content"].ToString();
				Obj.state = (( row["state"])==DBNull.Value)?0:Convert.ToInt32( row["state"]);
				Obj.utime = (( row["utime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["utime"]);
				Obj.dtime = (( row["dtime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["dtime"]);
				Obj.tag =  row["tag"].ToString();
				Obj.isHot = (( row["isHot"])==DBNull.Value)?0:Convert.ToInt32( row["isHot"]);
				Obj.username =  row["username"].ToString();
				Obj.flag = (( row["flag"])==DBNull.Value)?0:Convert.ToInt32( row["flag"]);
				Obj.RealName =  row["RealName"].ToString();
				Obj.Mobile =  row["Mobile"].ToString();
				Obj.Email =  row["Email"].ToString();
				Obj.SourceId = (( row["SourceId"])==DBNull.Value)?0:Convert.ToInt32( row["SourceId"]);
				Obj.hits = (( row["hits"])==DBNull.Value)?0:Convert.ToInt32( row["hits"]);
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  ask 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>ask 数据实体</returns>
		public askEntity Populate_askEntity_FromDr(IDataReader dr)
		{
			askEntity Obj = new askEntity();
			
				Obj.ID = (( dr["ID"])==DBNull.Value)?0:Convert.ToInt32( dr["ID"]);
				Obj.title =  dr["title"].ToString();
				Obj.content =  dr["content"].ToString();
				Obj.state = (( dr["state"])==DBNull.Value)?0:Convert.ToInt32( dr["state"]);
				Obj.utime = (( dr["utime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["utime"]);
				Obj.dtime = (( dr["dtime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["dtime"]);
				Obj.tag =  dr["tag"].ToString();
				Obj.isHot = (( dr["isHot"])==DBNull.Value)?0:Convert.ToInt32( dr["isHot"]);
				Obj.username =  dr["username"].ToString();
				Obj.flag = (( dr["flag"])==DBNull.Value)?0:Convert.ToInt32( dr["flag"]);
				Obj.RealName =  dr["RealName"].ToString();
				Obj.Mobile =  dr["Mobile"].ToString();
				Obj.Email =  dr["Email"].ToString();
				Obj.SourceId = (( dr["SourceId"])==DBNull.Value)?0:Convert.ToInt32( dr["SourceId"]);
				Obj.hits = (( dr["hits"])==DBNull.Value)?0:Convert.ToInt32( dr["hits"]);
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个ask对象
		/// </summary>
		/// <param name="iD">iD</param>
		/// <returns>ask对象</returns>
		public askEntity Get_askEntity (int iD)
		{
			askEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@ID",SqlDbType.Int)
			};
			_param[0].Value=iD;
			string sqlStr="select * from ask with(nolock) where ID=@ID";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_askEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表ask所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< askEntity> Get_askAll()
		{
			IList< askEntity> Obj=new List< askEntity>();
			string sqlStr="select * from ask";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_askEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="iD">iD</param>
        /// <returns>是/否</returns>
		public bool IsExistask(int iD)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@iD",SqlDbType.Int)
                                  };
            _param[0].Value=iD;
            string sqlStr="select Count(*) from ask where ID=@iD";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
